//走势图初始化
function initDataTrendChart(seriesArray, id, title, marginArray,yaxis) {
    Highcharts.setOptions({
        global: {
            useUTC: false
        }
    });
    // Create the chart
    return new Highcharts.Chart({
        chart: {
            renderTo: id, //要显示线状图的div的id
            type: 'line', //图表类型为线性图
            margin: marginArray,
            height:250,
        },
        title: {
            text: title
        },
        subtitle: {
            text: ''
        },
        credits: {  //版权信息
            enabled: true,
            href: '',
            text: ''
        },
        xAxis: {
            type: 'datetime',
            dateTimeLabelFormats: {
                day: '%H:%M'
            }
        },
        yAxis:yaxis,
        plotOptions: {
            line: {
                dataLabels: {
                    enabled: true
                },
                enableMouseTracking: false
            }
        },
        series: seriesArray
    });
}

//右侧页面加载
function loadRightPage(sms, push,push_app) {
    sms.div_obj.load(
        curPage, function () {
            window.sms_chart = initDataTrendChart(sms.array, 'main_content', "低调的监控", [40, 40, 60, 40],sms.yAxis); //初始化图片  point_num 一张图多少个x坐标点  time_interval 多长时间添加一个点
        });
    push.div_obj.load(
        curPage, function () {
            window.push_chart = initDataTrendChart(push.array, 'two_content', "", [5, 40, 60, 60],push.yAxis); //初始化图片  point_num 一张图多少个x坐标点  time_interval 多长时间添加一个点
        });
    push_app.div_obj.load(
        curPage, function () {
            window.push_app_chart = initDataTrendChart(push_app.array, 'three_content', "", [5, 40, 60, 60],push_app.yAxis); //初始化图片  point_num 一张图多少个x坐标点  time_interval 多长时间添加一个点
        });
    if (window.WebSocket) {
        if (window.socket_obj) {
            window.socket_obj.closeWebSocket();
        }
        window.socket_obj = new webSocketConnectInit({
            // reqUrl: ['ws://127.0.0.1:9696/websocket', ["room_name" + ' ' + "group"]]
            reqUrl: ['ws://day-ws.qianbao-inc.com/websocket', ["room_name" + ' ' + "group"]]
        });
        window.socket_obj.init();
    }
}

//刷新页面相关的数据
function refreshPageData(res, roomGroup) {
    res = eval('(' + res + ')');
    refreshChartTrend(res, roomGroup);
}

//刷新走势图数据  char类型导致 纵轴不支持小数 
function refreshChartTrend(res, roomGroup) {

    var x = (new Date()).getTime();
    // console.info(roomGroup+"     "+res.roomName+"  "+res.groupName);
    //页面和数据相符，则对数据内具体type进行判断和区分
    var y = res.count;
    if (res.type >= 0) {
        var procNum_series;
        if (res.groupName == 'sms') {
            procNum_series = window.sms_chart.series[res.type]; //进程数量
        }
        if (res.groupName == 'push') {
            procNum_series = window.push_chart.series[res.type]; //进程数量
        }
        if (res.groupName == 'push_app') {
            procNum_series = window.push_app_chart.series[res.type]; //进程数量
        }
        procNum_series.addPoint([x, y], true, true, false);
        console.info(x + "   " + y + "    " + res.type + "    " + procNum_series.data.length);
    }
}
